import React, { useState } from 'react';
import { IFormItem, Itype } from '@/base-ui/form';
import http from '@/services/request';
import { Space, Button, Select } from 'antd';
import { Input } from 'antd';
import { RightOutlined, UpOutlined } from '@ant-design/icons';

const { Option } = Select;

const { Search } = Input;

/* 搜索区域 */
// 这是高级检索的搜索配置项，一般要和你的表格的列关联
export const PageSearchConfig: IFormItem[] = [
  {
    type: 'input' as Itype,
    label: '车辆品牌',
    name: 'carBrand',
    placeholder: '请输入车辆品牌'
  },
  {
    type: 'input' as Itype,
    label: '车辆类型',
    name: 'carType',
    placeholder: '请输入车辆类型'
  },
  {
    type: 'input' as Itype,
    label: '车牌号',
    name: 'licensePlateNumber',
    placeholder: '请输入车牌号'
  },
  {
    type: 'input' as Itype,
    label: '车牌型号',
    name: 'carModel',
    placeholder: '请输入车牌型号'
  },

  {
    type: 'input' as Itype,
    label: '车辆颜色',
    name: 'carColor',
    placeholder: '请输入车辆颜色'
  },
  {
    type: 'input' as Itype,
    label: '可承载货物重量(kg)',
    name: 'carryFreightWeight',
    placeholder: '请输入可承载货物重量(kg)'
  },
  {
    type: 'input' as Itype,
    label: '运营证号',
    name: 'operationCertificateNumber',
    placeholder: '请输入运营证号'
  },
  {
    type: 'input' as Itype,
    label: '车库id',
    name: 'garageId',
    placeholder: '请输入车库id'
  },
  {
    type: 'input' as Itype,
    label: '车辆id',
    name: 'id',
    placeholder: '请输入车辆id'
  },
  {
    type: 'select' as Itype,
    label: '调试状态',
    name:'carStatus',
    placeholder: '请选择调试状态',
    options: [
      { label: '空闲', value: 'value1' },
      { label: '忙碌', value: 'value2' },
      { label: '维修', value: 'value3' },
      // { label: '20000件以上', value: 'value4' }
    ]
  },
  {
    type: 'input' as Itype,
    label: '备注',
    placeholder: '请输入备注'
  }

];

//高级检索
export const UseSearch = (props: any) => {
  return (
    <Space style={{ float: 'right' }}>
      {props.isMoreSearchShow ? (
        <Button
          type="link"
          size="large"
          onClick={() => {
            props.setisMoreSearchShow(false);
            props.setsearchMore(false);
          }}
        >
          收起
          <UpOutlined />
        </Button>
      ) : (
        <Button
          type="link"
          size="middle"
          onClick={() => {
            props.setisMoreSearchShow(true);
            props.setsearchMore(true);
          }}
        >
          高级检索
          <RightOutlined style={{ marginLeft: '1px' }} />
        </Button>
      )}
    </Space>
  );
};

// 这里是模糊查询 根据xxx进行查询
export const SearchSelector = (props: any) => {
  const [searchid, setsearchid]: any = useState('licensePlateNumber');
  return (
    <div
      style={{
        display: 'inline-block',
        width: '380px',
        marginBottom: 10,
        marginRight: 10,
        float: 'right'
      }}
    >
      <Select
        defaultValue={Options[1].label}
        style={{ width: 100 }}
        defaultActiveFirstOption
        onSelect={(value: string, option: any) => {
          setsearchid(option.key);
        }}
      >
        {Options.map((i) => (
          <Option value={i.label} key={i.value} children={null} />
        ))}
      </Select>
      <Search
        placeholder="请输入您要查的数据"
        onSearch={(e) => {
          // console.log(e);
          // console.log(searchid);
          if (e.trim() === '') {
            http.get('/logistics/carLogistics/get/1/10').then((res) => {
              props.dataSource(res.data.records);
            });
            return;
          }
          switch (searchid) {
            case 'carModel': {
              http(`/zk/carLogistics/list/carModel/${e}`).then((res) => {
                props.dataSource([res.data]);
              });
              break;
            }
            case 'licensePlateNumber': {
              http(`/zk/carLogistics/list/licensePlateNumber/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }
            case 'operationCertificateNumber': {
              http(`/zk/carLogistics/list/operationCertificateNumber/${e}`).then(
                (res) => {
                  props.dataSource(res.data);
                }
              );
              break;
            }

            default: {
              break;
            }
          }
        }}
        style={{ width: '280px' }}
        enterButton
      />
    </div>
  );
};
export const Searchdow = () => {
  return;
};

const Options = [
  { label: '车辆型号', value: 'carModel', onClick: (e: any) => {} },
  { label: '车牌号', value: 'licensePlateNumber', onClick: (e: any) => {} },
  { label: '运营证号', value: 'operationCertificateNumber', onClick: (e: any) => {} }

];

/* 表格区域 */

//复选框的接口
export interface DataType {
  id: number;
  key: React.Key;
  name: string;
  age: number;
  address: string;
}
